export default {
  chnNumChar : ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"],
  chnUnitSection : ["", "万", "亿", "万亿", "亿亿"],
  chnUnitChar : ["", "十", "百", "千"],

  SectionToChinese:function(section){//形参
    let strIns = '', chnStr = '';
    let unitPos = 0;
    let zero = true;
    while(section > 0) {
      let v = section % 10;
      if (v === 0) {
        if (!zero) {
          zero = true;
          chnStr = this.chnNumChar[v] + chnStr;
        }
      } else {
        zero = false;
        strIns = this.chnNumChar[v];
        strIns += this.chnUnitChar[unitPos];
        chnStr = strIns + chnStr;
      }
      unitPos++;
      section = Math.floor(section / 10);
    }
    console.log(chnStr);
    return chnStr;
  },

  NumberToChinese:function (num) {
    let unitPos = 0;
    let strIns = '', chnStr = '';
    let needZero = false;
    if (num === 0) {
      return this.chnNumChar[0];
    }
    while (num > 0) {
      let section = num % 10000;
      if (needZero) {
        chnStr = this.chnNumChar[0] + chnStr;
      }
      strIns = this.SectionToChinese(section);
      strIns += (section !== 0) ? this.chnUnitSection[unitPos] : this.chnUnitSection[0];
      chnStr = strIns + chnStr;
      needZero = (section < 1000) && (section > 0);
      num = Math.floor(num / 10000);
      unitPos++;
    }
    return chnStr;
  },
  //电价限制，正数，小数点前6位数小数点后4位
  validateElectricityPrice:function(number){
    const pattern = /^(?!0\d{5})([1-9]\d{0,5}(\.\d{1,4})?|0\.\d{1,4})$/;
    return pattern.test(number);
  },
  //费用限制，正数，小数点前6位数小数点后2位
  validateDecimal:function(number){
    const pattern = /^\d{1,6}(?:\.\d{1,2})?$/;
    return pattern.test(number);
  },
  //限制输入中文
  validateChinese:function(input){
    const pattern = /^[\u4e00-\u9fa5]+$/;
    return pattern.test(input);
  },
  //限制输入长度10位
  validateLength10:function(input){
    const pattern = /^.{1,10}$/;
    return pattern.test(input);
  },
  //限制输入长度20位
  validateLength20:function(input){
    const pattern = /^.{1,20}$/;
    return pattern.test(input);
  },
  //限制输入长度60位
  validateLength60:function(input){
    const pattern = /^.{1,60}$/;
    return pattern.test(input);
  },
  //限制输入纯数字
  validateDigits:function(input) {
    const pattern = /^[0-9]+$/;
    return pattern.test(input);
  },
  //限制输入正整数
  validatePositiveInteger:function(input) {
    const pattern = /^[1-9]\d*$/;
    return pattern.test(input);
  },
  //限制输入正整数且不能超过8位数
  validatePositiveIntegerLength8:function(input) {
    const pattern = /^[1-9]\d{0,7}$/;
    return pattern.test(input);
  },
  //限制不能输入特殊字符
  validateNoSpecialChars(input) {
    const pattern = /^[^\s!@#$%^&*()_+=\[\]{}|\\:;"'<>,.?/~`]+$/;
    return pattern.test(input);
  },
  //限制只能输入中文和英文
  validateChineseAndEnglish(input) {
    const pattern = /^[\u4e00-\u9fa5a-zA-Z]+$/;
    return pattern.test(input);
  },
  //限制只能输入中文和英文
  validateEnglishAndDigits(input) {
    const pattern = /^[a-zA-Z0-9]+$/;
    return pattern.test(input);
  },
}
